/*<!-- saved from url=(0013)about:internet -->*/
//*** Initializations



//Adds an option to a select box
function addOption(selectbox,text,value)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

//Adds all appropriate days, months and years as Date of Birth options
function addOptions_list() {

	//Adding all month options
	for (var i=0; i < month.length; ++i){
	
	addOption(document.forms["myForm"]["month"], month[i], month[i]);
	}
	
	//Adding all year options
	for(var i=0; i< year.length; ++i) {
	
	addOption(document.forms["myForm"]["year"], year[i], year[i]);
	
	}
	
	//Adding all day options
	for(var i=1; i< day.length; ++i) {
	
	addOption(document.forms["myForm"]["day"], day[i], day[i]);
	
	}
	
	for(var i=0; i<job.length; ++i) {
		
	addOption(document.forms["myForm"]["job"], job[i], job[i]);
	}
	

} 

/* Field and Roles*/
var Computers = new Array("Programmer","Technitian","Avi Sofer","IT Manager");
var Labour = new Array("Construction Worker","Firefighter","Maitenance");
var Prostitution = new Array("Pimp","Bitch");
var isCheckedField=0;
/*
function check_field()
{
	if(isCheckedField==0)
	{
		document.getElementById('fielddiv').style.visibility= 'visible';
		isCheckedField=1;
	}
		
	else if(isCheckedField==1)
	{
		document.getElementById('fielddiv').style.visibility= 'hidden';
		document.getElementById('rolediv').style.visibility= 'hidden';
		isCheckedField=0;
	}
		
}*/

var isCheckedAverage=0;
function show_average()
{	
	if(isCheckedField==0)
	{
		document.getElementById('fielddiv').style.visibility= 'visible';
		isCheckedField=1;
	}
		
	else if(isCheckedField==1)
	{
		document.getElementById('fielddiv').style.visibility= 'hidden';
		document.getElementById('rolediv').style.visibility= 'hidden';
		isCheckedField=0;
	}
}

function show_role()
{	
	var selection = document.forms["myForm"]["fieldcbox"].value;
	if(selection=="computers")
		add_comp();
	else if(selection=="labour")
		add_labour();
	else if(selection=="prost")
		add_prost();
}

function add_comp() {

	document.forms["myForm"]["rolecbox"].options.length=0;
	document.getElementById('rolediv').style.visibility= 'visible';
	for(var i=0; i<Computers.length; ++i) {
		
	addOption(document.forms["myForm"]["rolecbox"], Computers[i], Computers[i]);
	}
	

} 

function add_labour() {

	document.forms["myForm"]["rolecbox"].options.length=0;
	document.getElementById('rolediv').style.visibility= 'visible';
	for(var i=0; i<Labour.length; ++i) {
		
	addOption(document.forms["myForm"]["rolecbox"], Labour[i], Labour[i]);
	}
	

} 

function add_prost() {

	document.forms["myForm"]["rolecbox"].options.length=0;
	document.getElementById('rolediv').style.visibility= 'visible';
	for(var i=0; i<Prostitution.length; ++i) {
		
	addOption(document.forms["myForm"]["rolecbox"], Prostitution[i], Prostitution[i]);
	}
	

}
/*End of Field and Roles*/

/*Education*/
var OrtBraude = new Array("Software Engineering", "Electrical Engineering", "Biotechnology Engineering");
var BGU = new Array("Software Engineering", "Electrical Engineering", "Biotechnology Engineering","Chemical Engineering","Social Studies");
var Haifa = new Array("Computer Science", "Political Science","Economics");
var TelAviv = new Array("Social Studies","Software Engineering", "Electrical Engineering", "Biotechnology Engineering","Computer Science", "Political Science","Economics");
var Hebrew = new Array("Economics","Social Studies","Software Engineering","Computer Science", "Political Science");
var Technion = new Array("Computer Science","Software Engineering","Industrial Engineering","Electrical Engineering","Chemical Engineering");
var isCheckedEducation=0;

function check_education()
{
	if(isCheckedEducation==0)
	{
		document.getElementById('institutediv').style.visibility= 'visible';
		isCheckedEducation=1;
	}
		
	else
	{
		document.getElementById('institutediv').style.visibility= 'hidden';
		document.getElementById('coursediv').style.visibility= 'hidden';
		isCheckedEducation=0;
	}
		
}

function show_course()
{	
	var selection = document.forms["myForm"]["institutecbox"].value;
	//var selection = myForm.institutecbox.value;
	if(selection=="ortbraude")
		add_braude();
	else if(selection=="technion")
		add_technion();
	else if(selection=="haifauni")
		add_haifa();
	else if(selection=="telavivuni")
		add_telaviv();
	else if(selection=="hebrewuni")
		add_hebrew();
	else if(selection=="bgu")
		add_bgu();
}

function add_braude() {

	document.forms["myForm"]["coursecbox"].options.length=0;
	document.getElementById('coursediv').style.visibility= 'visible';
	for(var i=0; i<OrtBraude.length; ++i) {
		
	addOption(document.forms["myForm"]["coursecbox"], OrtBraude[i], OrtBraude[i]);
	}
} 
function add_technion() {

	document.forms["myForm"]["coursecbox"].options.length=0;
	document.getElementById('coursediv').style.visibility= 'visible';
	for(var i=0; i<Technion.length; ++i) {
		
	addOption(document.forms["myForm"]["coursecbox"], Technion[i], Technion[i]);
	}

} 

function add_haifa() {

	document.forms["myForm"]["coursecbox"].options.length=0;
	document.getElementById('coursediv').style.visibility= 'visible';
	for(var i=0; i<Haifa.length; ++i) {
		
	addOption(document.forms["myForm"]["coursecbox"], Haifa[i], Haifa[i]);
	}

} 

function add_telaviv() {

	document.forms["myForm"]["coursecbox"].options.length=0;
	document.getElementById('coursediv').style.visibility= 'visible';
	for(var i=0; i<TelAviv.length; ++i) {
		
	addOption(document.forms["myForm"]["coursecbox"], TelAviv[i], TelAviv[i]);
	}

} 

function add_hebrew() {

	document.forms["myForm"]["coursecbox"].options.length=0;
	document.getElementById('coursediv').style.visibility= 'visible';
	for(var i=0; i<Hebrew.length; ++i) {
		
	addOption(document.forms["myForm"]["coursecbox"], Hebrew[i], Hebrew[i]);
	}

} 

function add_bgu() {

	document.forms["myForm"]["coursecbox"].options.length=0;
	document.getElementById('coursediv').style.visibility= 'visible';
	for(var i=0; i<BGU.length; ++i) {
		
	addOption(document.forms["myForm"]["coursecbox"], BGU[i], BGU[i]);
	}

} 


/*End of Education*/

/* Average*/
var isCheckedAvg=0;

function check_average()
{
	if(isCheckedAvg==0)
	{
		document.getElementById('averagediv').style.visibility= 'visible';
		isCheckedAvg=1;
	}
		
	else
	{
		document.getElementById('averagediv').style.visibility= 'hidden';
		isCheckedAvg=0;
	}
		
}
/*End of Average*/

/*Experience*/
var isCheckedExp=0;
function check_experience()
{
	if(isCheckedExp==0)
	{
		document.getElementById('experiencediv').style.visibility= 'visible';
		isCheckedExp=1;
	}
		
	else
	{
		document.getElementById('experiencediv').style.visibility= 'hidden';
		isCheckedExp=0;
	}
}

/*End of experience*/

/*Location*/
var isCheckedLocation=0;
function check_location()
{
	if(isCheckedLocation==0)
	{
		document.getElementById('locationdiv').style.visibility= 'visible';
		isCheckedLocation=1;
	}
		
	else
	{
		document.getElementById('locationdiv').style.visibility= 'hidden';
		isCheckedLocation=0;
	}
}

/*End of Location*/


//Function checks if a string contains any special characters (string is not a word)
//Returns - 'true' if special char was found in String (not word), 'false' - otherwise
function notAword(str)
{
	return /[^a-zA-Z]/.test(str);
}





//E-mail validation
function val_email() 
{
	alert("in email");
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
	var email=document.getElementById("email").value;
	var res=emailPattern.test(email);
	if(res==false)
	{	
		document.getElementById("emailerror").style.visibility = "visible";
		isOK = false;	
	}
	
	else
	{
		document.getElementById("iderror").style.visibility = "hidden";
	}
	
}

function CheckAvailable()
{
        var uname = document.getElementById('uname').value;
        alert(uname);
        var xmlhttp;
		if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
         // alert(xmlhttp.responseText);
        	if (xmlhttp.readyState==4&& xmlhttp.status == 200)
            {
        	  		
        	  		alert(xmlhttp.responseText);
        	  		if(xmlhttp.responseText == 'false')
                    {
                        document.getElementById('usernameerror').style.visibility= 'visible';                   
                    }
                    else
                    {
                        document.getElementById('usernameerror').style.visibility= 'hidden';
                    }
                }
          };
        xmlhttp.open("GET","./name_available.php?username="+uname,true);
        xmlhttp.send();
}